package com.example.springbootdemo2.config;


import com.example.springbootdemo2.proer.MyProperty;
import com.example.springbootdemo2.service.MyStarterServcice;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
@ConditionalOnClass({MyStarterServcice.class})
@EnableConfigurationProperties(MyProperty.class)
public class MyStarterAutoConfig {

    @Resource
    private MyProperty myProperty;

    // MyStartService

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "yyl",value = "enabled",havingValue = "true")
    // yyl.test.enabled=true
    public MyStarterServcice getMyStartService(){

        return new MyStarterServcice(myProperty.getConfig());

    }

}
